var http = require('http')
var mysql= require('mysql')
//创建数据库连接
var connection = mysql.createConnection({
  host     : 'localhost',
  user     : 'root',
  password : '123456',
  database : 'mysql'
});
//开始连接
connection.connect();
http.createServer(function(request,response){
	//响应头设置
	response.writeHead(200,{'Content-Type':'text/plain;charset=UTF-8'});
	//查
	var  sql = 'SELECT * FROM states';
	connection.query(sql,function (err, result) {
	        if(err){
	          console.log('出错');
	          console.log('[SELECT ERROR] - ',err.message);
	          return;
	        }
	       console.log(JSON.stringify(result));
	       response.end(JSON.stringify({
	       		status:1,
	       		list:result
	       }))
	});
}).listen(8000)